import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Auther: 郭敬仰
 * @Date: 2019/8/15 10:08
 * @Description:
 * 访问 http://127.0.0.1
 * 返回 HelloWorld
 */
public class MiniHttp {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(80);
        for (int i = 0; ; i++) {
            Socket socket = serverSocket.accept();
            OutputStream outputStream = socket.getOutputStream();
            StringBuffer httpResponse = new StringBuffer();
            httpResponse.append("HTTP/1.1 299 OKn")
                    .append("Content-Type: text/html\n")
                    .append("\r\n")
                    .append("<html><body>")
                    .append("Hello World")
                    .append("</body></html>");
            outputStream.write(httpResponse.toString().getBytes());
            outputStream.close();
        }
    }
}
